<template>
    <div class="searchDialog">
        <div class="e-form">
            <el-form label-width="120px" :model="searchForm">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="申请日期：" prop="signingStartDate" label-width="200">
                            <el-date-picker
                                type="date"
                                placeholder="请选择日期"
                                value-format="yyyy-MM-dd"
                                v-model="searchForm.startTime"
                                :clearable="false"
                                style="width: 47%"
                            ></el-date-picker>
                            <div class="separ el-icon-minus"></div>
                            <el-date-picker
                                type="date"
                                placeholder="请选择日期"
                                value-format="yyyy-MM-dd"
                                v-model="searchForm.endTime"
                                :clearable="false"
                                style="width: 47%"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="申请机构：" prop="orgIds" label-width="200">
                            <ComInputSelectUnit
                                :orgName.sync="searchForm.applyOrgName"
                                :orgId.sync="searchForm.applyOrgId"
                                :SelectedIDs="
                                    searchForm.applyOrgId !== '' ? [searchForm.applyOrgId] : []
                                "
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="拟招标项目名称：" prop="orgIds" label-width="200">
                            <el-input v-model="searchForm.tenderName" placeholder="请填写">
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="采购方式：" prop="contractState">
                            <check-all
                                :chackdData="options.tenderForm"
                                @checkdData="onCheckTenderForm"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="招标状态：" prop="contractState">
                            <check-all
                                :chackdData="options.tenderState2"
                                @checkdData="onCheckTenderState"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <!-- <div class="footer-btn">
           <div class="buttons">
                <el-button type="primary" size="small" class="btn-blue">重置</el-button>
                <el-button
                    type="primary"
                    size="small"
                    class="btn-blue"
                >保存</el-button>
                <el-button size="small" @click="handleClose">取消</el-button>
            </div>
        </div> -->
        <div style="display: none">{{ localSearchData }}</div>
        <!-- <el-button @click="test">测试</el-button> -->
    </div>
</template>

<script>
import { mapMutations, mapState } from 'vuex'
import applyRequest from '@/api/tender/apply.js'
// eslint-disable-next-line no-unused-vars
import { selectDataClient, openAppClient } from '@/utils/common'
import ComInputSelectUnit from '@/pages/bidding/common/inputSelectUnit.vue'
import CheckAll from '@/components/common/checkAll'

export default {
    components: {
        CheckAll,
        ComInputSelectUnit
    },
    data () {
        return {
            searchForm: {
                applyOrgName: '',
                applyOrgId: '',
                endTime: '',
                name: '',
                limit: 20,
                page: 1,
                startTime: '',
                tenderForm: [],
                tenderName: '',
                tenderState: [],
            },
            // type: 1 //合同名称：1，分包合同,2，其他合同,3，服务采购合同
        }
    },
    computed: {
        ...mapState({
            options: state => state.biddingApplication.dictionaries
            // userInfo: state => state.userInfo
        }),
        localSearchData () {
            // 默认设置搜索标志为false，则不进行搜索回调
            const searchForm = this.searchForm
            searchForm.searching = false
            this.setSearchData(searchForm)
            return searchForm
        },
        // ...mapState({
        //     state: state => state.equip.equipData.state, //通用流程状态
        //     stateArr: state => state.contract.ctClassify.stateArr, //分包合同状态
        //     subTypeFormObj: state => state.contract.ctClassify.subTypeFormObj, //分包合同类型
        //     otherSubTypeFormObj: state => state.contract.ctClassify.otherSubTypeFormObj, //其他合同类型
        //     serviceTypeList: state => state.contract.ctClassify.serviceTypeList //其他合同类型
        // })
    },
    mounted () {
        this.type = this.$route.query.type
    },
    methods: {
        ...mapMutations(['setSearchData', 'setSelectedInfo']),
        async tenderApplyListByEntity () {
            // const { pageSize: limit, currentPage: page } = this.pagination
            await applyRequest
                .tenderApplyListByEntity(
                    // limit,
                    // page,
                    this.searchForm
                )
                .then(() => {
                    // this.tableData = res.list
                    // this.pagination.total = res.totalCount
                    // this.getButtonState()
                })
        },
        onCheckTenderForm (data) {
            this.searchForm.tenderForm = data
        },
        // 招标状态没草稿，最后获取的值加1
        onCheckTenderState (data) {
            this.searchForm.tenderState = data
            this.searchForm.tenderState = this.searchForm.tenderState.map(item => item + 1)
            console.log('this.searchForm.tenderState', this.searchForm.tenderState)
        },
        test () {
            // console.log(this.searchForm)
            this.tenderApplyListByEntity()
        },
        onSelectOrg () {
            selectDataClient({
                SelectServiceToken: '/hr/org/getChildrenOrg', // 客户端对应方法名
                IsSingleMode: false, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id(注意：是上一次已选中的id，不是要传的参数，如果第一次选，则传[])
                InitParamsStr: '', // 接口参数(name为模拟参数)
                Title: '选择机构' // 标题
            }).then(val => {
                this.searchForm.orgIds = [val[0].orgId]
                this.searchForm.orgName = val[0].orgName
            })
        },
        onCheckStateObj (data) {
            this.searchForm.contractState = data
        },
        onCheckSubTypeFormObj (data) {
            this.searchForm.contractTypeIds = data
        },
        handleClose () {
            this.$router.push('/')
        }
    }
}
</script>

<style lang="scss"></style>
